#include <stdio.h>
#include "usbfunctions.h"

//-----------------MAIN--------------------
int main(int argc, char **argv)
{
	int prescale = DEFAULT_PRESCALE;
	if(argc > 1){
		prescale = atoi(argv[1]);
		if(prescale < 0 || prescale > 7) prescale = DEFAULT_PRESCALE;
	}
	printf("Using prescale %d\n", prescale);
	
	//connect to device (exits if it's not found)
	usb_dev_handle* handle = connect_device();
    printf("connected.\n");

	//clear and open data.csv
	FILE* data_file = newDatafile();
	
	//send next_pulse with the prescale value we want
    uint8_t buffer[SAMPLE_COUNT];
    int recv, i;
    for(i=0;i<100;i++){
		grabData(handle, buffer);
		writeBuffer(buffer, SAMPLE_COUNT, data_file);
        //nsleep(1000000);
    }
    fclose(data_file);
    usb_close(handle);
}

